package com.tars.txappstart.interceptors;

import com.tars.txtm.trasactional.MyTransactionalManager;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author: Franz 2022/3/19
 */
@Component
public class TxInterceptor implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        String txGroupID = request.getHeader("txGroupID");
        MyTransactionalManager.setCurrentTxGroupID(txGroupID);
        return true;
    }

}
